{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "01_Python",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "metadata": {
        "id": "bOChJSNXtC9g",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Introduction to Python"
      ]
    },
    {
      "metadata": {
        "id": "OLIxEDq6VhvZ",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "<img src=\"https://raw.githubusercontent.com/GokuMohandas/practicalAI/master/images/logo.png\" width=150>\n",
        "\n",
        "In this lesson we will learn the basics of the Python programming language (version 3). We won't learn everything about Python but enough to do some basic machine learning.\n",
        "\n",
        "<img src=\"https://raw.githubusercontent.com/GokuMohandas/practicalAI/master/images/python.png\" width=350>\n",
        "\n",
        "\n"
      ]
    },
    {
      "metadata": {
        "id": "VoMq0eFRvugb",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "#  Variables"
      ]
    },
    {
      "metadata": {
        "id": "qWro5T5qTJJL",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Variables are objects in Python that can hold anything with numbers or text. Let's look at how to create some variables."
      ]
    },
    {
      "metadata": {
        "id": "0-dXQiLlTIgz",
        "colab_type": "code",
        "outputId": "38d1f8a5-b067-416b-b042-38a373624a8b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Numerical example\n",
        "x = 5\n",
        "print (x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "5\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "5Ym0owFxTkjo",
        "colab_type": "code",
        "outputId": "72c2781a-4435-4c21-b15a-4c070d47bd86",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Text example\n",
        "x = \"hello\"\n",
        "print (x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "hello\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "1a4ZhMV1T1-0",
        "colab_type": "code",
        "outputId": "0817e041-5f79-46d8-84cc-ee4aaea0eba2",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Variables can be used with each other\n",
        "a = 1\n",
        "b = 2\n",
        "c = a + b\n",
        "print (c)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "3\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "nbKV4aTdUC1_",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Variables can come in lots of different types. Even within numerical variables, you can have integers (int), floats (float), etc. All text based variables are of type string (str). We can see what type a variable is by printing its type."
      ]
    },
    {
      "metadata": {
        "id": "c3NJmfO4Uc6V",
        "colab_type": "code",
        "outputId": "04b91fa4-51af-48f4-e9ac-591b5bf3e714",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        }
      },
      "cell_type": "code",
      "source": [
        "# int variable\n",
        "x = 5\n",
        "print (x)\n",
        "print (type(x))\n",
        "\n",
        "# float variable\n",
        "x = 5.0\n",
        "print (x)\n",
        "print (type(x))\n",
        "\n",
        "# text variable\n",
        "x = \"5\" \n",
        "print (x)\n",
        "print (type(x))\n",
        "\n",
        "# boolean variable\n",
        "x = True\n",
        "print (x)\n",
        "print (type(x))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "5\n",
            "<class 'int'>\n",
            "5.0\n",
            "<class 'float'>\n",
            "5\n",
            "<class 'str'>\n",
            "True\n",
            "<class 'bool'>\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "6HPtavfdU8Ut",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "It's good practice to know what types your variables are. When you want to use numerical operations on them, they need to be compatible. "
      ]
    },
    {
      "metadata": {
        "id": "8pr1-i7IVD-h",
        "colab_type": "code",
        "outputId": "c2bce48d-b69f-4aab-95c1-9e588f67a6c3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        }
      },
      "cell_type": "code",
      "source": [
        "# int variables\n",
        "a = 5\n",
        "b = 3\n",
        "print (a + b)\n",
        "\n",
        "# string variables\n",
        "a = \"5\"\n",
        "b = \"3\"\n",
        "print (a + b)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "8\n",
            "53\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "q4R_UF6PVw4V",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "#  Lists"
      ]
    },
    {
      "metadata": {
        "id": "LvGsQBj4VjMl",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Lists are objects in Python that can hold a ordered sequence of numbers **and** text."
      ]
    },
    {
      "metadata": {
        "id": "9iPESkq9VvlX",
        "colab_type": "code",
        "outputId": "67dfbe9f-d4cb-4a62-a812-7c5c8a01c2fa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Creating a list\n",
        "list_x = [3, \"hello\", 1]\n",
        "print (list_x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[3, 'hello', 1]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "0xC6WvuwbGDg",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        ""
      ]
    },
    {
      "metadata": {
        "id": "7lbajc-zV515",
        "colab_type": "code",
        "outputId": "4345bbe0-0f0c-4f84-bcf2-a76130899f34",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Adding to a list\n",
        "list_x.append(7)\n",
        "print (list_x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[3, 'hello', 1, 7]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "W0xpIryJWCN9",
        "colab_type": "code",
        "outputId": "a7676615-aff1-402f-d41f-81d004728f94",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        }
      },
      "cell_type": "code",
      "source": [
        "# Accessing items at specific location in a list\n",
        "print (\"list_x[0]: \", list_x[0])\n",
        "print (\"list_x[1]: \", list_x[1])\n",
        "print (\"list_x[2]: \", list_x[2])\n",
        "print (\"list_x[-1]: \", list_x[-1]) # the last item\n",
        "print (\"list_x[-2]: \", list_x[-2]) # the second to last item"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "list_x[0]:  3\n",
            "list_x[1]:  hello\n",
            "list_x[2]:  1\n",
            "list_x[-1]:  7\n",
            "list_x[-2]:  1\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "VSu_HNrnc1WK",
        "colab_type": "code",
        "outputId": "3c40cce2-9599-41aa-b01c-7c6f39329212",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 85
        }
      },
      "cell_type": "code",
      "source": [
        "# Slicing\n",
        "print (\"list_x[:]: \", list_x[:])\n",
        "print (\"list_x[2:]: \", list_x[2:])\n",
        "print (\"list_x[1:3]: \", list_x[1:3])\n",
        "print (\"list_x[:-1]: \", list_x[:-1])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "list_x[:]:  [3, 'hello', 1, 7]\n",
            "list_x[2:]:  [1, 7]\n",
            "list_x[1:3]:  ['hello', 1]\n",
            "list_x[:-1]:  [3, 'hello', 1]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "dImY-hVzWxB4",
        "colab_type": "code",
        "outputId": "8394f232-aa11-4dbd-8580-70adb5adc807",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Length of a list\n",
        "len(list_x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "4"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        }
      ]
    },
    {
      "metadata": {
        "id": "3-reXDniW_sm",
        "colab_type": "code",
        "outputId": "382d1a40-ad1a-49f7-f70f-2c2a02ffd88d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Replacing items in a list\n",
        "list_x[1] = \"hi\"\n",
        "print (list_x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[3, 'hi', 1, 7]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "X8T5I3bjXJ0S",
        "colab_type": "code",
        "outputId": "1ede1c5c-c6ea-452f-b13d-ff9efd3d53b0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Combining lists\n",
        "list_y = [2.4, \"world\"]\n",
        "list_z = list_x + list_y\n",
        "print (list_z)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[3, 'hi', 1, 7, 2.4, 'world']\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "ddpIO6LLVzh0",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Tuples"
      ]
    },
    {
      "metadata": {
        "id": "CAZblq7oXY3s",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Tuples are also objects in Python that can hold data but you cannot replace their values (for this reason, tuples are called immutable, whereas lists are known as mutable)."
      ]
    },
    {
      "metadata": {
        "id": "G95lu8xWXY90",
        "colab_type": "code",
        "outputId": "c23250e5-534a-48e6-ed52-f034859f73c2",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Creating a tuple\n",
        "tuple_x = (3.0, \"hello\")\n",
        "print (tuple_x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(3.0, 'hello')\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "kq23Bej1acAP",
        "colab_type": "code",
        "outputId": "34edfbff-dbc0-4385-a118-7f1bcc49e84f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Adding values to a tuple\n",
        "tuple_x = tuple_x + (5.6,)\n",
        "print (tuple_x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(3.0, 'hello', 5.6)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "vyTmOc6BXkge",
        "colab_type": "code",
        "outputId": "dadeac9a-4bb4-43a3-ff40-e8ca6a05ba2c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 164
        }
      },
      "cell_type": "code",
      "source": [
        "# Trying to change a tuples value (you can't)\n",
        "tuple_x[1] = \"world\""
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-15-86abc19d8025>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtuple_x\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"world\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
          ]
        }
      ]
    },
    {
      "metadata": {
        "id": "UdlJHkwZV3Mz",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Dictionaries"
      ]
    },
    {
      "metadata": {
        "id": "azp3AoxYXS26",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Dictionaries are Python objects that hold key-value pairs. In the example dictionary below, the keys are the \"name\" and \"eye_color\" variables. They each have a value associated with them. A dictionary cannot have two of the same keys. "
      ]
    },
    {
      "metadata": {
        "id": "pXhNLbzpXXSk",
        "colab_type": "code",
        "outputId": "e4bb80e5-4e7b-4cbb-daa6-77490ab25145",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "cell_type": "code",
      "source": [
        "# Creating a dictionary\n",
        "goku = {\"name\": \"Goku\",\n",
        "        \"eye_color\": \"brown\"}\n",
        "print (goku)\n",
        "print (goku[\"name\"])\n",
        "print (goku[\"eye_color\"])\n"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "{'name': 'Goku', 'eye_color': 'brown'}\n",
            "Goku\n",
            "brown\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "1HXtX8vQYjXa",
        "colab_type": "code",
        "outputId": "ad8d1a0f-d134-4c87-99c1-0f77140f2de0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Changing the value for a key\n",
        "goku[\"eye_color\"] = \"green\"\n",
        "print (goku)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "{'name': 'Goku', 'eye_color': 'green'}\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "qn33iB0MY5dT",
        "colab_type": "code",
        "outputId": "bd89033e-e307-4739-8c1d-f957c32385b5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Adding new key-value pairs\n",
        "goku[\"age\"] = 24\n",
        "print (goku)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "{'name': 'Goku', 'eye_color': 'green', 'age': 24}\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "g9EYmzMKa9YV",
        "colab_type": "code",
        "outputId": "4b9218b9-2f4d-4287-932a-caba430713aa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Length of a dictionary\n",
        "print (len(goku))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "3\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "B-DInx_Xo2vJ",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# If statements"
      ]
    },
    {
      "metadata": {
        "id": "ZG_ICGRGo4tY",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "You can use `if` statements to conditionally do something."
      ]
    },
    {
      "metadata": {
        "id": "uob9lQuKo4Pg",
        "colab_type": "code",
        "outputId": "21d40476-ea6a-4149-f744-0119d0894d77",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# If statement\n",
        "x = 4\n",
        "if x < 1:\n",
        "    score = \"low\"\n",
        "elif x <= 4:\n",
        "    score = \"medium\"\n",
        "else:\n",
        "    score = \"high\"\n",
        "print (score)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "medium\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "vwsQaZqIpfJ3",
        "colab_type": "code",
        "outputId": "1f190875-b910-4e54-a58a-d4230b7c8169",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# If statment with a boolean\n",
        "x = True\n",
        "if x:\n",
        "    print (\"it worked\")"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "it worked\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "sJ7NPGEKV6Ik",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Loops"
      ]
    },
    {
      "metadata": {
        "id": "YRVxhVCkn0vc",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "In Python, you can use `for` loop to iterate over the elements of a sequence such as a list or tuple, or use `while` loop to do something repeatedly as long as a condition holds."
      ]
    },
    {
      "metadata": {
        "id": "OB5PtyqAn8mj",
        "colab_type": "code",
        "outputId": "b4595670-99d4-473e-b299-bf8cf47f1d81",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "cell_type": "code",
      "source": [
        "# For loop\n",
        "x = 1\n",
        "for i in range(3): # goes from i=0 to i=2\n",
        "    x += 1 # same as x = x + 1\n",
        "    print (\"i={0}, x={1}\".format(i, x)) # printing with multiple variables"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "i=0, x=2\n",
            "i=1, x=3\n",
            "i=2, x=4\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "6XyhCrFeoGj4",
        "colab_type": "code",
        "outputId": "2427ae1f-85f7-4888-f47f-8de1992a84c3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "cell_type": "code",
      "source": [
        "# Loop through items in a list\n",
        "x = 1\n",
        "for i in [0, 1, 2]:\n",
        "    x += 1\n",
        "    print (\"i={0}, x={1}\".format(i, x))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "i=0, x=2\n",
            "i=1, x=3\n",
            "i=2, x=4\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "5Tf2x4okp3fH",
        "colab_type": "code",
        "outputId": "1ac41665-2f35-4c7d-e9f5-22614d3ba35c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "cell_type": "code",
      "source": [
        "# While loop\n",
        "x = 3\n",
        "while x > 0:\n",
        "    x -= 1 # same as x = x - 1\n",
        "    print (x)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "2\n",
            "1\n",
            "0\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "gJw-EDO9WBL_",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Functions"
      ]
    },
    {
      "metadata": {
        "id": "hDIOUdWCqBwa",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Functions are a way to modularize reusable pieces of code. "
      ]
    },
    {
      "metadata": {
        "id": "iin1ZXmMqA0y",
        "colab_type": "code",
        "outputId": "3bfae4a7-482b-4d43-8350-f8bb5e8a35ac",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Create a function\n",
        "def add_two(x):\n",
        "    x += 2\n",
        "    return x\n",
        "\n",
        "# Use the function\n",
        "score = 0\n",
        "score = add_two(x=score)\n",
        "print (score)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "2\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "DC6x3DMrqlE3",
        "colab_type": "code",
        "outputId": "8965bfab-3e20-41ae-9fc1-f22a7d4f3333",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# Function with multiple inputs\n",
        "def join_name(first_name, last_name):\n",
        "    joined_name = first_name + \" \" + last_name\n",
        "    return joined_name\n",
        "\n",
        "# Use the function\n",
        "first_name = \"Goku\"\n",
        "last_name = \"Mohandas\"\n",
        "joined_name = join_name(first_name=first_name, last_name=last_name)\n",
        "print (joined_name)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Goku Mohandas\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "lBLa1n54WEd2",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Classes"
      ]
    },
    {
      "metadata": {
        "id": "mGua8QnArAZh",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Classes are a fundamental piece of object oriented programming in Python."
      ]
    },
    {
      "metadata": {
        "id": "DXmPwI1frAAd",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# Creating the class\n",
        "class Pets(object):\n",
        "  \n",
        "    # Initialize the class\n",
        "    def __init__(self, species, color, name):\n",
        "        self.species = species\n",
        "        self.color = color\n",
        "        self.name = name\n",
        "\n",
        "    # For printing  \n",
        "    def __str__(self):\n",
        "        return \"{0} {1} named {2}.\".format(self.color, self.species, self.name)\n",
        "\n",
        "    # Example function\n",
        "    def change_name(self, new_name):\n",
        "        self.name = new_name"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "ezQq_Fhhrqrv",
        "colab_type": "code",
        "outputId": "bf159745-99b1-4e33-af4d-f63924a1fe74",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        }
      },
      "cell_type": "code",
      "source": [
        "# Creating an instance of a class\n",
        "my_dog = Pets(species=\"dog\", color=\"orange\", name=\"Guiness\",)\n",
        "print (my_dog)\n",
        "print (my_dog.name)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "orange dog named Guiness.\n",
            "Guiness\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "qTinlRj1szc5",
        "colab_type": "code",
        "outputId": "80939a31-0242-4465-95ff-da0e5caaa67c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        }
      },
      "cell_type": "code",
      "source": [
        "# Using a class's function\n",
        "my_dog.change_name(new_name=\"Charlie\")\n",
        "print (my_dog)\n",
        "print (my_dog.name)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "orange dog named Charlie.\n",
            "Charlie\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "kiWtd0aJtNtY",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Additional resources"
      ]
    },
    {
      "metadata": {
        "id": "cfLF4ktmtSC3",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "This was a very quick look at Python and we'll be learning more in future lessons. If you want to learn more right now before diving into machine learning, check out this free course: [Free Python Course](https://www.codecademy.com/learn/learn-python)"
      ]
    }
  ]
}